package com.chang.rentmall.controllers;

import com.chang.rentmall.beans.MessageBean;
import com.chang.rentmall.forms.GetShopsFormBean;
import com.chang.rentmall.servicesImpl.ShopServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ShopController {
    @Autowired
    ShopServiceImpl shopService;

    @RequestMapping(value = "shop/create", method = {RequestMethod.POST})
    public MessageBean addShop (@RequestBody GetShopsFormBean getShopsFormBean) {
        return shopService.addShop(getShopsFormBean.getForm());
    }

    @RequestMapping(value = "shop/list", method = {RequestMethod.POST})
    public MessageBean getShopList (@RequestBody GetShopsFormBean getShopsFormBean) {
        return shopService.getShops(getShopsFormBean);
    }

    @RequestMapping(value = "shop/update", method = {RequestMethod.POST})
    public MessageBean updateShop (@RequestBody GetShopsFormBean getShopsFormBean) {
        return shopService.updateShop(getShopsFormBean.getForm());
    }

    @RequestMapping(value = "shop/detail", method = {RequestMethod.POST})
    public MessageBean getShopDetail (@RequestBody GetShopsFormBean getShopsFormBean) {
        return shopService.getShopById(getShopsFormBean.getQuery().getId());
    }

    @RequestMapping(value = "shop/detail/usr", method = {RequestMethod.POST})
    public MessageBean getUserShopDetail (@RequestBody GetShopsFormBean getShopsFormBean) {
        return shopService.getShopByUserId(getShopsFormBean.getQuery().getId());
    }

}
